# Maintainer: Feng Shu <tumashu@163.com>

_realname=marisa
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.2.6
pkgrel=3
pkgdesc="Static and space-efficient trie data structure library (mingw-w64)"
url="https://github.com/s-yata/marisa-trie"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("marisa-trie-$pkgver.tar.gz::https://github.com/s-yata/marisa-trie/archive/v${pkgver}.tar.gz"
       "001-tools-makefile.patch")
sha256sums=('1063a27c789e75afa2ee6f1716cc6a5486631dcfcb7f4d56d6485d2462e566de'
            'd3ec2637462ac3331f0c6bcba9b8552bca4819321df265b3fd895547bbf75717')

prepare() {
  cd "marisa-trie-${pkgver}"
  patch -p0 -i ${srcdir}/001-tools-makefile.patch
  autoreconf -fiv
}

build() {
  [[ -d build-${MSYSTEM} ]] && rm -rf build-${MSYSTEM}
  mkdir build-${MSYSTEM} && cd build-${MSYSTEM}

  case ${MINGW_CHOST} in
    i686*)
      local _conf=''
    ;;
    x86_64*)
      local _conf='--enable-sse2'
    ;;
  esac

  ../marisa-trie-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    ${_conf} \
    --disable-shared

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
